<template>
    <div class="content">
        <van-popup style="height: 100%; width: 70%; background-color: #2e323b" v-model:show="show" position="left"
            class="leftcontent">
            <div class="shichang">{{ $t('市場') }}</div>
            <van-search :clearable="false" v-model="value" shape="round" background="#2e323b" :placeholder="$t('搜索')" />
            <div class="tab">
                <div @click="lefttabchange(0)" :style="{ color: lefttab === 0 ? '#f2ce3d' : '#fff' }" class="item">{{
                    $t('自選') }}</div>
                <div @click="lefttabchange(1)" :style="{ color: lefttab === 1 ? '#f2ce3d' : '#fff' }" class="item">USDT
                </div>
            </div>
            <div class="title">
                <div class="left">{{ $t('交易對') }}</div>
                <div class="right">{{ $t('交易對/24H漲跌幅') }}</div>
            </div>
            <div class="cont">
                <div class="item" v-for="item in 10">
                    <div class="left">
                        <span style="color: #fff;">BTC</span>
                        <span style="color: #556566;">/USDT</span>
                    </div>
                    <div class="right">
                        <div class="top">26794.53</div>
                        <div :style="{ color: leftnum > 0 ? '#2ebd85' : '#f5465d' }" class="btm">{{ leftnum }}%</div>
                    </div>
                </div>
            </div>
        </van-popup>
        <div class="tab">
            <div class="tabitem">
                <div @click="tabCheck(0)"
                    :style="{ color: tab === 1 ? '#929899' : '#fff', 'background-color': tab === 1 ? '#212429' : '#2e323b' }"
                    class="item">
                    {{ $t('幣幣') }}
                </div>
                <div @click="tabCheck(1)"
                    :style="{ color: tab === 0 ? '#929899' : '#fff', 'background-color': tab === 0 ? '#212429' : '#2e323b' }"
                    class="item">
                    {{ $t('合約') }}</div>
            </div>
        </div>
        <div class="title">
            <div class="left" @click="onshow">
                <van-icon name="exchange" color="#fff" size="24px" />
                <div class="text1">BTC/USDT</div>
                <div :style="{ color: num > 0 ? '#2ebd85' : '#f5465d' }" class="text2">{{ num }}%</div>
            </div>
            <div class="right">
                <img @click="goto('/view')" v-if="tab === 0" src="@/assets/trade/link.png" alt="">
                <van-rate v-else class="star" clearable color="#ffd21e" void-color="#eee" :count="1" v-model="score" />
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const tab = ref(0)
const num = ref(0.73)
const score = ref(0)
const show = ref(false)
const value = ref('')
const lefttab = ref(0)
const leftnum = ref(0.73)

function onshow() {
    show.value = true
}

function tabCheck(index) {
    if (tab.value == index) return
    tab.value = index
    if (index === 0) {
        router.push('/page/trade/exchange')
    } else {
        router.push('/page/trade/contract')
    }
}

function lefttabchange(index) {
    if (lefttab.value == index) return
    lefttab.value = index
}

function goto(url) {
    router.push(url)
}
</script>

<style lang="scss" scoped>
::v-deep input {
    caret-color: #fff;
    color: #fff;
}

.van-search {
    background-color: #232830;
}

::v-deep .van-search__content {
    background: #232830;
}

.content {
    background-color: #17171a;
    padding: 44px 15px 15px 15px;



    .leftcontent {
        .shichang {
            font-size: 22px;
            color: #fff;
            margin: 40px 0 0 15px;
        }

        .tab {
            display: flex;
            align-items: center;
            margin-top: 14px;
            padding: 0 15px;
            width: 100%;
            height: 21px;
            font-size: 15px;
            color: #fff;

            .item {
                display: flex;
                justify-content: center;
                align-items: center;
                padding: 0 5px;
            }
        }

        .title {
            width: 100%;
            height: 25px;
            padding: 0 15px;
            font-size: 12px;
            color: #d5d5d5;

            .left {}

            .right {}
        }

        .cont {
            width: 100%;
            padding: 0 15px;
            box-sizing: border-box;

            .item {
                display: flex;
                justify-content: space-between;
                align-items: center;
                width: 100%;
                height: 50px;

                .left {
                    font-size: 14px;
                }

                .right {
                    .top {
                        font-size: 14px;
                        color: #fff;
                    }

                    .btm {
                        float: right;
                        font-size: 12px;
                    }
                }
            }

        }
    }

    .tab {
        width: 100%;
        height: 59px;
        padding: 12px 0;
        box-sizing: border-box;

        .tabitem {
            display: flex;
            width: 100%;
            height: 100%;
            border: 1px solid #324040;
            border-radius: 8px;
            padding: 1px;
            box-sizing: border-box;

            .item {
                display: flex;
                justify-content: center;
                align-items: center;
                width: 50%;
                border-radius: 8px;
                font-size: 15px;
            }
        }
    }

    .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        height: 54px;
        padding: 10px 0;
        box-sizing: border-box;

        .left {
            display: flex;
            align-items: center;

            .text1 {
                margin-left: 10px;
                font-size: 17px;
                color: #fff;
            }

            .text2 {
                margin-left: 5px;
                font-size: 12px;
            }
        }

        .right {
            img {
                width: 24px;
                height: 24px;
            }
        }
    }
}
</style>